function fooderimg(){
    var url = $("#imgupload").val();
    var element = document.getElementById('headportrait');
    var pos=url.lastIndexOf("\\");
    var ab =  url.substring(pos+1);
    if(ab == undefined || ab==""){
        swal({
            title:"提示",
            text:"未选择文件",
            type:"warning",
            showCancelButton:false,
            confirmButtonText:"确定"
        });
    }else if(!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(url)){
        // var strFileName=url.replace(/^.+?\\([^\\]+?)(\.[^\.\\]*?)?$/gi,"$1");
        // var FileExt=url.replace(/.+\./,"");
        //var absoluteurl = strFileName+FileExt;
        swal({
            title:"提示",
            text:"格式不正确",
            type:"warning",
            showCancelButton:false,
            confirmButtonText:"确定"
        });
    }else{
        // //更改显示图片
        var r= new FileReader();
        f=document.getElementById('imgupload').files[0];
        r.readAsDataURL(f);
        r.onload=function  (e) {
            document.getElementById('headportrait').src=this.result;
        };
    }

}
function liuupdate() {
    //表单参数
    var $updateform = $("#userupdate").find("form");
    var params = $updateform.serialize();
    var brithday = $updateform.find("[name= birthday]").val();
    var name = $updateform.find("[name=name]").val();
    var sex = null;
    var phone = $updateform.find("[name= phone]").val();
    var address = $updateform.find("[name=address]").val();
    var loginName = $("#loginName").html();
    //图片名
    var url = $updateform.find("[name=tijiao]").val();
    var element = document.getElementById('headportrait');
    var pos=url.lastIndexOf("\\");
    var headerimg =  url.substring(pos+1);
    swal({
        text:"确定要修改吗",
        type:"question",
        showCancelButton:"true",
        showConfirmButton:"true",
        confirmButtonText:"确定",
        cancelButtonText:"取消",
    }).then(function (a) {
        if(a==true){
            var $updateform = $("#userupdate").find("form");
            var $fileurl = $updateform.find("[name=tijiao]");
            $fileurl.change(
                function () {
                    $updateform.ajaxSubmit({
                        url:ctx+"/sys/user/createimg",
                        dataType:"json",
                        success:function (arr) {
                            $(arr).each(function(){
                                var $imgStr = $("<img class='img-thumbnail'/>");
                                $imgStr.attr("src",ctx+"/cardPic/"+this);
                                $imgStr.appendTo("#picview");
                                var $hidden = $("<input type='hidden' name='picName'/>");
                                $hidden.val(this);
                                $hidden.appendTo("#myform");
                            });
                        }, uploadProgress: function(event, position, total, percentComplete) {//上传的过程
                            //position 已上传了多少
                            //total 总大小
                            $("#pbar").show();
                            var percentVal = percentComplete+'%';
                            $("#pbar .progress-bar").width(percentVal);
                            $("#pbar .progress-bar").html(percentVal);
                        }
                    })
                }
            )
            if(document.getElementById("sex").checked == true){
                sex = 1;
            }else{
                sex = 0;
            }
            $.post(ctx+"/sys/user/updateInLiu",{"loginName":loginName,"brithday":brithday,"name":name,"sex":sex,"phone":phone,"headerimg":headerimg,"address":address},function (data) {
                swal({
                    title:"信息提示!",
                    text:data,
                    type:"success",
                    allowOutsideClick:false
                }).then(function (okjian) {
                    if(okjian==true){
                        tiaoben();
                    }
                })
                $(document).keyup(function(event){
                    switch(event.keyCode) {
                        case 27:{
                            tiaoben();
                        }
                        case 116:{
                            tiaoben();
                        }
                    }
                });
            })
        }
    })
}

function tiaoben(){
    parent.parent.location.reload();
}
